# import time
# import win32clipboard
# from get_chrome import get_chrombrowser
# from selenium.webdriver.common.keys import Keys

# driver = get_chrombrowser()
# driver.get('https://pss-system.cponline.cnipa.gov.cn/seniorSearch')
# input('登录：')
# driver.get('https://pss-system.cponline.cnipa.gov.cn/seniorSearch')
# time.sleep(2)
# #设置复制内容Text
# Text="代理机构=(宜昌市三峡专利事务所) AND 代理人=(成钢) AND 申请日=2021-01-01:2022-12-31"
# #打开粘贴板
# win32clipboard.OpenClipboard()
# #清空粘贴板
# win32clipboard.EmptyClipboard()
# #设置复制的内容为Text
# win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,Text)
# #关闭粘贴板线程
# win32clipboard.CloseClipboard()
# #打开粘贴板
# win32clipboard.OpenClipboard()
# #获取粘贴板内容，传给参数data
# data=win32clipboard.GetClipboardData(win32clipboard.CF_TEXT)
# #输出粘贴板内容
# #需要关闭一下粘贴板线程
# win32clipboard.CloseClipboard()
# el = driver.find_element_by_xpath('//textarea[@id="textarea"]')
# el.clear()
# time.sleep(1)
# el.click()
# time.sleep(1)
# # #在网站主页输入Control+v模拟粘贴，然后执行搜索操作。
# el.send_keys(Keys.CONTROL, 'v')
# time.sleep(2)
# #通过回车键来代替单击操作，实现查询。
# el.send_keys(Keys.ENTER)
# time.sleep(1000)
# # driver.quit()


# el_person = chrome_browser.find_element_by_xpath('//span[text()=" 代理人"]/../following-sibling::div[1]/input')
# el_person.click()
# time.sleep(1)
# el_person.send_keys(person_name)
# time.sleep(1)
# el_agent = chrome_browser.find_element_by_xpath('//span[text()=" 代理机构"]/../following-sibling::div[1]/input')
# el_agent.click()
# time.sleep(1)
# el_agent.send_keys(agent_name)
# time.sleep(1)
# # 选取申请日期
# chrome_browser.find_element_by_xpath('//span[text()=" 申请日"]/../following-sibling::div[1]/div[@class="dropdown el-dropdown"]/span').click()
# time.sleep(0.5)
# chrome_browser.find_element_by_xpath('//div[@class="dropdownItem"]/span[text()=" : "])[2]').click()
# chrome_browser.find_element_by_xpath('//div[@class="el-date-picker__header"]/span[@role="button" and contains(text(),"年")]').click()
# time.sleep(0.5)
# chrome_browser.find_element_by_xpath('(//a[@class="cell" and text()="2021"])[2]').click()
# time.sleep(0.5)
# chrome_browser.find_element_by_xpath('//a[@class="cell" and text()="一月"])[2]').click()
# time.sleep(0.5)
# chrome_browser.find_element_by_xpath('')
# # 点击检索
# time.sleep(1)
# chrome_browser.find_element_by_xpath('//span[text()="检索"]/preceding-sibling::i[1]/..').click()
# time.sleep(random.randint(1,3))

# import pymysql

# db = pymysql.connect(host="localhost",
#                      user='root',
#                      port=3306,
#                      password='123456',
#                      database='big_data')
# cur = db.cursor()
# sql = r'''SELECT
# ins.`names`,
# ins.`certificate`,
# ins.`FilingNumber`,
# ins.`speciality`,
# if(ins.`practice`='None','',ins.`practice`) as practice,
# ins.`OrganizationCode`,
# hub.InstitutionName
# FROM institutionalagent as ins
# left join hubeiprovinceagency as hub
# on ins.OrganizationCode=hub.OrganizationCode'''
# cur.execute(sql)
# person_data = cur.fetchall()
# for item in person_data:
#     print(item)


# import requests
# import json
# authorization = r'Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJuZXVzb2Z0IiwiaWF0IjoxNjgyMzk0NzM5LCJleHAiOjE2ODI0MjM1MzksImFjY2Vzc190b2tlbiI6IjliYzAwYjk0LWRiNjQtNGNhYS04OThlLTA2NjdjNTdhYWNiOCIsInJlZnJlc2hfdG9rZW4iOiI5NjI3M2MyNS05OGE3LTRlNWQtOGJjYS0wMzUxODNjZmQxMTIiLCJ1c2VySWQiOiIxNTYwMDY1NDY2MCIsIkV4cGlyZXNfaW4iOjI4ODAwfQ.MgQNcnAIEhfsr4wWlxDoULmLZrUSKOrHowGAOrzLaURX7mRwwjdiCPj6YGkU2JX3p01AoZCqDCuhT66M_qbz0b9gKF8VZ81jI4kLw_Qm0b5GYqjsEskL1MV9P85GPXBQES--uak-m6gVJvkOAvdvefTRo7HH4DF7ii1YETWqnbw'
# application_number='2023103964101'
# headers = {'Accept': 'application/json, text/plain, */*', 'Accept-Encoding': 'gzip, deflate, br',
#                'Accept-Language': 'zh-CN,zh;q=0.9',
#                'Authorization': """%s""" % authorization,
#                'Cache-Control': 'no-cache',
#                'Connection': 'keep-alive',
#                'Content-Length': '30',
#                'Content-Type': 'application/json;charset=UTF-8',
#                'Host': 'cpquery.cponline.cnipa.gov.cn',
#                'Origin': 'https://cpquery.cponline.cnipa.gov.cn',
#                'Pragma': 'no-cache',
#                'Referer': 'https://cpquery.cponline.cnipa.gov.cn/detail/index?zhuanlisqh=%s&anjianbh' % application_number,
#                'Sec-Fetch-Dest': 'empty',
#                'Sec-Fetch-Mode': 'cors',
#                'Sec-Fetch-Site': 'same-origin',
#                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
#                'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
#                'sec-ch-ua-mobile': '?0',
#                'sec-ch-ua-platform': '"Windows"',
#                'userType': 'USER_RZ_DAILIJIG'}
# data = {"zhuanlisqh": application_number}
# status_post_url = r'https://cpquery.cponline.cnipa.gov.cn/api/view/gn/fyxx'
# patent_pay_res = requests.post(
#     status_post_url, headers=headers, data=json.dumps(data))
# patent_pay_res_json = patent_pay_res.json()
# print(patent_pay_res_json)
# patent_pay_data = patent_pay_res_json.get('data')
# yijiaofei_data = patent_pay_data.get('yijiaofei')
# yijiaofei_list = yijiaofei_data.get('svYijfList')
# yinjiaofei_data = patent_pay_data.get('yingjiaofei')
# yinjiaofei_list = yinjiaofei_data.get('svYingjfList')
# zhinafei_data = patent_pay_data.get('zhinajin')
# zhinafei_list = zhinafei_data.get('svZnjList')
# print(yinjiaofei_list)
# print(yijiaofei_list)
# print(zhinafei_list)
# if yinjiaofei_list == [] and yijiaofei_list == [] and zhinafei_list == []:
#     print('无信息')
# coding=gbk

# # redis_con = redis.Redis(host='121.4.69.146', password='xhhg123456',
# #                         port=6389, db=2, decode_responses=True)
import redis
redis_con = redis.Redis(host='127.0.0.1', password='',
                                     port=6379, db=2, decode_responses=True)
# import pandas as pd
# df = pd.read_excel('恩施土家族苗族自治州中心医院.xlsx')
# xhhg_list = set(list(df['申请号']))
# for app_num in xhhg_list:
#     redis_con.sadd("tmp_信合红谷接口查询", app_num)



import pymysql
sql = r'''
SELECT distinct zhuanlisqh FROM `yiyuan_pantent_list_xiehe_1128`
 '''
conn = pymysql.connect(host="localhost",
                       user='root',
                       port=3306,
                       password='123456',
                       database='big_data')
cur = conn.cursor()
cur.execute(sql)
data = cur.fetchall()
sqh_list = [sqh[0] for sqh in data]
for sqh in sqh_list:
    redis_con.sadd("tmp_信合红谷接口查询", sqh)

# res = redis_con.smembers('全部接口未查到')
# print(res)
# res={'2023112176653'}
# redis_con = redis.Redis(host='127.0.0.1', password='',
#                                      port=6379, db=2, decode_responses=True)
# for app_num in res:
#     redis_con.sadd("信合红谷接口查询", app_num)

# import json
# from playwright.sync_api import sync_playwright

# inst = 'XHHG'
# sqh = '2023100937367'
# storage_state_path = f'./auth/{inst}_state.json'
# with open(storage_state_path) as file:
#     storage_state= json.load(file)
#     origins= storage_state.get('origins')
#     local_stroge_list = [item.get('localStorage') for item in origins]
#     for local_stroge in local_stroge_list:
#         for item in local_stroge:
#             if item.get('name')=='ACCESS_TOKEN':
#                 authorization=item.get('value')
#                 print(authorization)
# print(f'成功读取{inst}登录信息')

# with sync_playwright() as p:
#     browser = p.firefox.launch(headless=False)
#     context = browser.new_context(
#         base_url='https://cpquery.cponline.cnipa.gov.cn', storage_state=storage_state_path)
#     context.set_default_timeout(600000)
#     context.set_default_navigation_timeout(600000)
#     page = context.new_page()
#     page.goto(
#         'https://cpquery.cponline.cnipa.gov.cn/chinesepatent/index')
#     page.wait_for_load_state()
#     api_request_context = context.request
#     headers = {
#         "Accept": "application/json, text/plain, */*",
#         "Content-Type": "application/json;charset=utf-8",
#         "Authorization": 'Bearer ' + authorization,
#         "userType": "USER_RZ_DAILIJIG"
#     }
#     fyxx_response = api_request_context.post(
#         '/api/view/gn/fyxx', data={'zhuanlisqh': sqh}, headers=headers)
#     # patent_pay_res_json = fyxx_response.json()
#     print(fyxx_response.text())


# import requests
# import json
# authorization = r'eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJuZXVzb2Z0IiwiaWF0IjoxNjg0NDc3NDE4LCJleHAiOjE2ODQ1MDYyMTgsImFjY2Vzc190b2tlbiI6IjVmOTk1NWEwLWVhMDMtNDM3OC05ZGVjLWI2YmY3OWNhMGFkNSIsInJlZnJlc2hfdG9rZW4iOiJkMmQ0MmM3OC0yZGIwLTQ2YWMtYTgyZi1lZWI5MGU5YWQ1OTQiLCJ1c2VySWQiOiIxNTYwMDY1NDY2MCIsIkV4cGlyZXNfaW4iOjI4ODAwfQ.Z3begT4RzteLqhsY3ZWiXuPJHPbj5kAG-wYmpTsBR5F5UEjKKthpv0kmA2DQcfpIkY-QxhR84AvRmCzR_tizPCDmKxd5aRT-TjGHo9s-Q5mAU6ZfMUou6CTbvwlPdKZQm6KGtxGJiJE4r68cOhclnCG0Budsnq_tc6gtx4PkmU4'

# headers = {
#     "Accept": "application/json, text/plain, */*",
#     "Content-Type": "application/json;charset=utf-8",
#     "Authorization": 'Bearer ' + authorization,
#     "language": "zh"
# }
# data = {
#     "executableSearchExp": "UWCMH4wzTOp4r6VJwvekgHvzh464NmELNdRdVnuZm0uwvZGzKbUYFl%2Br6txj0Qil3xqieP2Ov9JJedGGNnXTJA%3D%3D",
#     "parseSearchExp": "UWCMH4wzTOp4r6VJwvekgHvzh464NmELNdRdVnuZm0uwvZGzKbUYFl%2Br6txj0Qil3xqieP2Ov9JJedGGNnXTJA%3D%3D",
#     "searchExp": "v067rmslIMAOdeyv5fsyCYjXD6%2Fyk9EaNjzw3pbdMywRg%2FQIeqxYHcdpaZa%2FOpAMWUI5kHEf1WdlEjVWTrtyhg%3D%3D",
#     "sortFields": "-APD",
#     "pagination": {"page": 1, "limit": 10},
#     "dbName": "CNDB%2CWPDB",
#     "interfaceId": "2001154"}
# post_url = r'https://pss-system.cponline.cnipa.gov.cn/api/pubsearch-app-search/search/results/getResults'
# res = requests.post(post_url,headers=headers, data=json.dumps(data),
#                     allow_redirects=True)
# print(res.text)

# import pymysql
# select_sql = "SELECT distinct application_number FROM `external_orders`"
# con_mysql = pymysql.connect(host="112.125.25.114", port=3306, user='python',
#                             password='pythonselect', db="mykhadmin", use_unicode=True, charset='utf8')
# cur_m = con_mysql.cursor()
# cur_m.execute(select_sql)
# data_list = cur_m.fetchall()
# cur_m.close()
# con_mysql.close()
# print(f'共计:{len(data_list)}')
# print(data_list)
